'use strict';

const Service = require('egg').Service;

class UserService extends Service {
    async getuser(stu) {
        let res = await this.app.mysql.query(`select * from user2 where stu='${stu}'`);
        return res;
    }
  async registry(obj) {
    let {name,pwd,stu,role}  = obj;
    let res = await this.app.mysql.query(`insert into user2 (name,pwd,stu,role) values ('${name}','${pwd}','${stu}','${role}')`);
    return res;
  }
  async login(stu,pwd){
      let res =await this.app.mysql.query(`select * from user2 where stu='${stu}'and pwd='${pwd}'`);
      return res;
  }
  async getrole(rid){
    let res =await this.app.mysql.query(`select * from role where id='${rid}'`);
    return res;
  }
  async getmenu(rid){
    let pid = `select pid from role_power where rid=${rid}`;
        let sql = `select * from power where id in (${pid})`;
        let res = await this.app.mysql.query(sql);
        return res;
  }
  async getstudent(){
    let stus = `select stu from scorer`
    let sql= `select * from user2 where stu in (${stus}) and not role=1`;
    let res = await this.app.mysql.query(sql);
        return res;
  }
}

module.exports = UserService;
